NAME         sed - the stream editor

SYNOPSIS         sed [-n] [-g] [-e script] [-f sfilename] [filename ] ...

DESCRIPTION sed reads each filename line by line, edits each line according to a script of commands as specified by the ø-e and ø-f arguments and then copies the edited line to the standard output.

OPTIONS The ø-e option supplies a single edit command from the next argument; if there are several of these they are executed in the order in which they appear. If there is just one ø-e option and no -f's, the ø-e flag may be omitted. An ø-f option causes commands to be taken from the file sfilename; if there are several of these they are executed in the order in which they appear;  ø-e and ø-f commands may be mixed. The script or sfilename can be adjacent to the ø-e or ø-f or can be the next argument on the command line. The ø-g option causes sed to act as though every substitute command in the following script has a øg suffix. The ø-n option suppresses the default output.

SCRIPTS A script consists of commands of the following form: [address [,address] ] function [arguments] Normally sed cyclically copies a line of input into a current text buffer, then applies in sequence all commands whose addresses select that line and then copies the buffer to standard output and clears the buffer. The ø-n option suppresses normal output so that only commands which do output (e.g. p) cause any writing to occur. Also, some commands (øn, N) do their own line reads, and some others (ød, D) cause all commands following in the script to be skipped (the øD command also suppresses the clearing of the current text buffer that would normally occur before the next cycle). There is also a second buffer (called the `hold space' that can be copied or appended to or from or swapped with the current text buffer.

ADDRESSES An address is: a decimal number (which matches that numbered line where line numbers start at 1 and run cumulatively across files), or a ``$'' (which matches the last line of input), or a ``/regular expression/'' (which matches any line satisfying the expression. The following rules govern the address matching:
\begin{items}
\item A command line with no addresses selects every input line.
...
... that function apply to every line not selected by the address(es).
\end{items}
FUNCTIONS In the following list of functions, the maximum number of addresses permitted for each function is indicated in parentheses. An argument denoted text consists of one or more lines, with all but the last ending with `' to hide the newline. A command with this type argument must be the last on any command line or ø-e argument. Otherwise multiple commands may appear on a line separated by ``;" characters. A command may have a trailing comment indicated by a ``#'' character. Comment lines begin with a ``#''. Backslashes in text are treated as described in escape sequences below; they may be used to protect initial whitespace against the stripping that is done on every line of the script. An argument denoted label, rfile or wfile (which specify labels or file names) is not processed for escape sequences. Therefore a ``;" or a ``#" terminates the label or file name. This simplifies entering DOS style paths. Each wfile is created before processing begins. There can be at most 10 distinct wfile arguments.
\begin{flist}
\ia a text (1)
Append the {\it text\/} on output before reading...
...grouping started by a \lq \{'.
\ib ~ (0) An empty command is ignored.
\end{flist}
ESCAPE SEQUENCES The following escape sequences are used to represent unprintable characters in text, regular expressions and replacement text. It is ignored in labels and files. If the character following the `' is not list below the `' causes the character to be quoted during script input. The øl command also uses this convention.
a bell(07) b backspace(08) e escape(27) f formfeed(12) n newline(10) r return(13) t tab(09) v verticaltab(11) xhh the ASCII character corresponding to 2 hex digits hh.
the backslash itself.

REGULAR EXPRESSIONS (REs) Regular expressions can be built up from the following ``single-character" REs:
\begin{llist}
\item[c] Any ordinary character not listed below. An ordinary cha...
...alent to the last {\it RE\/}
encountered in the input processing.
\end{llist}

ERROR MESSAGES The following error messages may appear during the compilation phase of sed processing all cause sed to terminate:
\begin{elist}
\item[sed: bad expression {\it hh\/}] The escape sequence of \lq\lq \b...
... {\it option\/} is not
allowed on the invoking line for {\bf sed}
\end{elist}

The following warning may be displayed during compilation:
\begin{elist}
\item[sed: Label not used {\it label}] The listed {\it label\/} was defined
but never referenced.
\end{elist}

During the actual editing the following fatal errors can occur:
\begin{elist}
\item[sed: append too long after line {\it number\/}] A \o G \o H...
...d command caused
more than 20 reads and appends for the give line
\end{elist}

BUGS I tried to fix every problem I could find, but I believe the follow bugs still exist in this verstion:
\begin{items}
\item The {\tt getline} routine can overflow the buffer before ch...
...
\item All output files are overwritten even when there are errors
\end{items}

COMPATIBILITY This version of sed is a modification of the Internet supplied GNU version. That version was reverse-engineered from BSD 4.1 UNIX sed. The following changes, modifications and improvements have been made:
\begin{items}
\item There is no hidden length limit (40 in BSD {\bf sed}) on {...
...ata.
\item In all contexts a blank file name means {\it stdout\/}.
\end{items}

This version otherwise appears to be equivalent to the UNIX version on the Sun4 computer. That is I believe anything that sed did on that system, this version of sed will do the same on either a Sun4 or a PC under DOS. If anyone can really explain what sed is really supposed to do as explained in the UNIX documentation I would appreciate the information. The manual page refers to ed for further details which is ambiguous at best and the description I read for either the øD command or the options for the øs command were not understandable by me.

I would appreciate any comments, suggestions and even bug reports. I sometimes can be reached on INTERNET (the fiscal year is almost over), but you can always contact me by mail or phone
    Howard Helman helman@elm.sdd.trw.com
    Box 340
    Manhattan Beach, CA 90266
    213.372.5387 or after 11/1/91 310.372.5387